package com.farm.resume.dao.impl;

import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.sql.result.DataResult;
import com.farm.core.sql.utils.HibernateSQLTools;
import com.farm.resume.dao.ResumeappraisalDaoInter;
import com.farm.resume.domain.Resumeappraisal;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;











@Repository
public class ResumeappraisalDaoImpl
  extends HibernateSQLTools<Resumeappraisal>
  implements ResumeappraisalDaoInter
{
  @Resource(name="sessionFactory")
  private SessionFactory sessionFatory;
  
  public void deleteEntity(Resumeappraisal resumeappraisal)
  {
    Session session = this.sessionFatory.getCurrentSession();
    session.delete(resumeappraisal);
  }
  

  public int getAllListNum()
  {
    Session session = this.sessionFatory.getCurrentSession();
    SQLQuery sqlquery = session.createSQLQuery("select count(*) from farm_code_field");
    BigInteger num = (BigInteger)sqlquery.list().get(0);
    return num.intValue();
  }
  

  public Resumeappraisal getEntity(String resumeappraisalid)
  {
    Session session = this.sessionFatory.getCurrentSession();
    return (Resumeappraisal)session.get(Resumeappraisal.class, resumeappraisalid);
  }
  

  public Resumeappraisal insertEntity(Resumeappraisal resumeappraisal)
  {
    Session session = this.sessionFatory.getCurrentSession();
    session.save(resumeappraisal);
    return resumeappraisal;
  }
  

  public void editEntity(Resumeappraisal resumeappraisal)
  {
    Session session = this.sessionFatory.getCurrentSession();
    session.update(resumeappraisal);
  }
  

  public Session getSession()
  {
    return this.sessionFatory.getCurrentSession();
  }
  
  public DataResult runSqlQuery(DataQuery query)
  {
    try
    {
      return query.search(this.sessionFatory.getCurrentSession());
    } catch (Exception e) {}
    return null;
  }
  


  public void deleteEntitys(List<DBRule> rules)
  {
    deleteSqlFromFunction(this.sessionFatory.getCurrentSession(), rules);
  }
  

  public List<Resumeappraisal> selectEntitys(List<DBRule> rules)
  {
    return selectSqlFromFunction(this.sessionFatory.getCurrentSession(), rules);
  }
  

  public void updataEntitys(Map<String, Object> values, List<DBRule> rules)
  {
    updataSqlFromFunction(this.sessionFatory.getCurrentSession(), values, rules);
  }
  

  public int countEntitys(List<DBRule> rules)
  {
    return countSqlFromFunction(this.sessionFatory.getCurrentSession(), rules);
  }
  
  public SessionFactory getSessionFatory() {
    return this.sessionFatory;
  }
  
  public void setSessionFatory(SessionFactory sessionFatory) {
    this.sessionFatory = sessionFatory;
  }
  
  protected Class<?> getTypeClass()
  {
    return Resumeappraisal.class;
  }
  
  protected SessionFactory getSessionFactory()
  {
    return this.sessionFatory;
  }
  
  public Resumeappraisal getResumeappraisalEntityByUser(String userid)
  {
    Session session = this.sessionFatory.getCurrentSession();
    Query query = session.createQuery("from Resumeappraisal where userid=?");
    query.setString(0, userid);
    
    List<Resumeappraisal> list = query.list();
    if (list.size() > 0) {
      return (Resumeappraisal)list.get(0);
    }
    return null;
  }
}
